Inheritance is one of the most valuable concepts in object-oriented programming. It’s a way to categorize and reuse code by creating collections of
attributes and behaviors called classes, which can be based on previously created classes.
But abusing this concept by creating a deep inheritance tree can lead to complex and unmaintainable source code. Often, an inheritance tree
becoming too deep is the symptom of systematic use of "inheritance" when other approaches like "composition" would be better suited.
This rule raises an issue when the inheritance tree, starting from Object
, has a greater depth than is allowed.
The rule has one parameter to filter out classes of the count of inheritance. The following rules apply to define this parameter:
-
?
matches a single character
-
*
matches zero or more characters
-
**
matches zero or more packages
Examples:
-
java.fwk.AbstractFwkClass
: the count stops when AbstractFwkClass class is reached.
-
java.fwk.*
: any member of java.fwkPackage package is reached.
-
java.fwk.**
: same as above, but including sub-packages.